import json
import requests
from log.log import Log

from ERRO.erro import *
import pymysql
from config.Readconfig import *
log=Log()

host=Read_config().url
config_header=Read_config().header
class Request_processing:
    """请求"""
    def __init__(self):

        self.request=requests.session()
        # curr=pymysql.connect(**sql)#连接数据库
        # self.sql=curr.cursor()#光标
    def post(self,api=None,header={},data=None,json_format=None):
        try:
            log.log_post(host+api,data)
            return self.request.post(url=host+api, headers={**config_header,**header}, data=json.dumps(data),json=json_format,verify=False)
        except:
            raise http
    def get(self,api=None,header={},parma=None):
        try:
            log.log_get(url=host+api)
            return self.request.get(url=host+api,headers={**config_header,**header},params=parma,verify=False)
        except requests.exceptions.MissingSchema:
            raise http
    def put(self,api=None,header={},data=None,json_format=None):
        try:
            log.log_put(host+api,data)
            return self.request.put(url=host+api,headers={**config_header,**header},data=json.dumps(data),json=json_format,verify=False)
        except:
            raise http
    def delete(self,api=None,header={},data=None):
        try:
            log.log_delete(host+api)
            return self.request.delete(url=host+api,headers={**config_header,**header},verify=False)
        except:
            raise http
    # def sql(self):

    #     curr = pymysql.connect(**sql)  # 连接数据库
    #     self.sql = curr.cursor()  # 光标
    #     return self.sql
    # def ex_sql(self,value=None):
    #     self.sql().execute(value)
    # def sql_assert(self):
    #     self.ex_sql()
    #     return self.sql().fetchall()



